﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace _2014112107
{
    public partial class UserInsert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           

        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112107;uid=2014112107;pwd=19951106";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                StringBuilder SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("INSERT INTO  project");
                SqlStringBuilder.Append("                (日期, 项目1, 支出额, 项目2,收入额, 备注) ");
                SqlStringBuilder.Append("VALUES   (@Date,@Project1,@Num1,@Project2,@Num2,@Memo) ");

                string strSql = SqlStringBuilder.ToString();
                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlParameter pmsDate = new SqlParameter("@Date", this.txtDate.Text);
                SqlParameter pmsProject1 = new SqlParameter("@Project1", this.txtProject1.Text);
                SqlParameter pmsNum1 = new SqlParameter("@Num1", this.txtNum1.Text);
                SqlParameter pmsProject2 = new SqlParameter("@Project2", this.txtProject2.Text);
                SqlParameter pmsNum2 = new SqlParameter("@Num2", this.txtNum2.Text);
                SqlParameter pmsMemo = new SqlParameter("@Memo", this.txtMemo.Text);
                cmd.Parameters.Add(pmsDate);
                cmd.Parameters.Add(pmsProject1);
                cmd.Parameters.Add(pmsNum1);
                cmd.Parameters.Add(pmsProject2);
                cmd.Parameters.Add(pmsNum2);
                cmd.Parameters.Add(pmsMemo);


                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    this.lblInfo.Text = "新增失败！";
                }
                else
                {
                    this.lblInfo.Text = "新增" + iUpd.ToString() + "条记录！";
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

       
    }
}